﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.Data;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using WindowsForms.AOnline.Presenter.Dictionary.FixedAssetCategory;
using WindowsForms.AOnline.View.Dictionary;
using WindowsForms.AOnline.WindowsForm.BaseUserControls;
using WindowsForms.AOnline.WindowsForm.FormBase.PropertyGrid;

namespace WindowsForms.AOnline.WindowsForm.UserControl.Dictionary
{
    public partial class UserControlFixedAssetCategoryList : BaseTreeListUserControl, IFixedAssetCategorysView
    {
        private readonly FixedAssetCategorysPresenter _fixedAssetCategorysPresenter;
        public UserControlFixedAssetCategoryList()
        {
            InitializeComponent();
            _fixedAssetCategorysPresenter = new FixedAssetCategorysPresenter(this);
        }

        public IList<Model.BusinessObjects.Dictionary.FixedAssetCategoryModel> FixedAssetCategorys
        {
            set
            {
                treeList.DataSource = value;
                ColumnsCollection.Add(new XtraColumn { ColumnName = "FixedAssetCategoryCode", ColumnCaption = "Mã nhóm", ColumnPosition = 1, ColumnVisible = true, ColumnWith = 100, Alignment = HorzAlignment.Center });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "FixedAssetCategoryName", ColumnCaption = "Tên nhóm", ColumnPosition = 2, ColumnVisible = true, ColumnWith = 400, Alignment = HorzAlignment.Center });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "LifeTime", ColumnCaption = "Thời gian sử dụng", ColumnPosition = 3, ColumnVisible = true, ColumnWith = 80, Alignment = HorzAlignment.Center, ColumnType = UnboundColumnType.Decimal });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "DepreciationRate", ColumnCaption = "Tỷ lệ khấu hao", ColumnPosition = 4, ColumnVisible = true, ColumnWith = 80, Alignment = HorzAlignment.Center, ColumnType = UnboundColumnType.Integer });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsActive", ColumnCaption = "Ngừng sử dụng", ColumnVisible = true, ColumnPosition = 5, ColumnWith = 80, Alignment = HorzAlignment.Center });

                ColumnsCollection.Add(new XtraColumn { ColumnName = "Grade", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsParent", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "OrgPriceAccountCode", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "DepreciationAccountCode", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "OrgPriceAccountCode", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "CapitalAccountCode", ColumnVisible = false });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "UnitId", ColumnVisible = false });
            }
        }

        /// <summary>
        /// Loads the data into tree.
        /// </summary>
        protected override void LoadDataIntoTree(int page)
        {
            TotalPage = _fixedAssetCategorysPresenter.GetPageSize();
            if (page <= TotalPage)
            {
                _fixedAssetCategorysPresenter.Display(page);
            }
        }

        /// <summary>
        /// Deletes the tree.
        /// </summary>
        protected override string DeleteTree()
        {
            return new FixedAssetCategoryPresenter(null).Delete(int.Parse(PrimaryKeyValue));
        }

        private void treeList_NodeCellStyle(object sender, DevExpress.XtraTreeList.GetCustomNodeCellStyleEventArgs e)
        {
            //e.Appearance.Font = Convert.ToBoolean(e.Node["IsParent"]) ? new Font(e.Appearance.Font.FontFamily, e.Appearance.Font.Size, FontStyle.Bold) : new Font(e.Appearance.Font.FontFamily, e.Appearance.Font.Size, FontStyle.Regular);
            e.Appearance.Font = Convert.ToBoolean(e.Node["IsParent"])
                                  ? new Font(e.Appearance.Font.FontFamily, e.Appearance.Font.Size, FontStyle.Regular)
                                  : new Font(e.Appearance.Font.FontFamily, e.Appearance.Font.Size, FontStyle.Bold);
        }
    }
}
